package com.apache.oscache;

import com.apache.uct.common.LoginUser;

public class OsCacheManager {

    private BaseOsCache newsCache;

    private static OsCacheManager instance;

    public OsCacheManager() {
        //这个根据配置文件来，初始BaseCache而已
        newsCache = new BaseOsCache("mobile", 30 * 60);//缓存半小时
    }

    public static synchronized OsCacheManager getInstance() {
        if (instance == null) {
            instance = new OsCacheManager();
        }
        return instance;
    }

    public String getSessionTokenId(String sessionId) {
        try {
            return String.valueOf(newsCache.get(sessionId));
        } catch (Exception e) {
            return null;
        }
    }

    public void putSessionTokenId(String sessionId, String tokenId) {
        newsCache.put(sessionId, tokenId);
    }

    public void putLoginUser(String tokenId, LoginUser loginUser) {
        newsCache.put(tokenId, loginUser);
    }

    public void removeLoginUser(String tokenId) {
        newsCache.remove(tokenId);
    }

    public LoginUser getLoginUser(String tokenId) {
        try {
            return (LoginUser) newsCache.get(tokenId);
        } catch (Exception e) {
            return null;
        }
    }

    public void putCustomerUser(String key, Object customer) {
        newsCache.put(key, customer);
    }

    public void removeCustomerUser(String key) {
        newsCache.remove(key);
    }

    public Object getCustomerUser(String key) {
        try {
            return newsCache.get(key);
        } catch (Exception e) {
            return null;
        }
    }

    public void removeAllNews() {
        newsCache.removeAll();
    }
}
